<?php

namespace App\Models;


class Sweep extends Orm
{
    //

    protected $table = 'sweep';
    protected $dateFormat = 'U';
    public $timestamps = true;
    protected $casts = [
        'sign_pics' => 'json',
    ];

    public function setSignPicsAttribute($value)
    {
        $this->dealSetImageAttribute('sign_pics', $value);
    }

    public function userInfo()
    {
        return $this->belongsTo(Users::class, 'user_id');
    }

    public function entrySurvey()
    {
        return $this->hasOne(EntrySurvey::class, 'sweep_id');
    }

    public function projectInfo()
    {
        return $this->belongsTo(Project::class, 'project_id');
    }

    public function teamInfo()
    {
        return $this->belongsTo(Team::class, 'team_id');
    }

    public function getSignCoordAttribute()
    {
        list($lng,$lat) = explode(',', $this->attributes['sign_coord']);
        $lat = floatval($lat);
        $lng = floatval($lng);
        return compact("lat", "lng");
    }
}
